package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.labillusion.core.platform.web.pagination.PaginationForm;
import com.labillusion.core.util.UUIDUtils;
import com.ujoku.context.ActionContext;
import com.ujoku.dao.CartDao;
import com.ujoku.dao.MyListDao;
import com.ujoku.domain.*;
import com.ujoku.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 14-10-19.
 */
@Service
public class MyListServiceImpl extends BaseServiceImpl<MyList> implements MyListService<MyList> {

    @Autowired
    private MyListDao dao;

    @Override
    protected BaseDao<MyList> getBaseDao() {
        return dao;
    }

    @Autowired
    private MyListItemService myListItemService;

    @Autowired
    private RepurchaseItemService repurchaseItemService;

    @Override
    public MyList selectMyListByMemberId(int memberId){
        Map<String,Object> query = new HashMap<>();
        query.put("memberId", memberId);
        MyList myList = super.selectOne(query);
        if(myList != null){
            myList.setMyListItemList(myListItemService.selectMyListItem(myList.getId()));
        }

        return myList;
    }

    @Override
    public MyList selectOnlyMyListByMemberId(int memberId){
        Map<String,Object> query = new HashMap<>();
        query.put("memberId", memberId);
        MyList myList = super.selectOne(query);

        return myList;
    }

    @Override
    public int getRepurchaseItemCount(PaginationForm form, MyList myList){
        Map<String,Object> query = form.getQueryMap();
        query.put("myListId", myList.getId());

        int count = repurchaseItemService.selectCount(query);

        return count;
    }

    @Override
    public int getItemCount(PaginationForm form, MyList myList) {
        Map<String,Object> query = form.getQueryMap();
        query.put("myListId", myList.getId());
        //总数
        int count = myListItemService.selectCount(query);
        return count;
    }

    @Override
    public int getItemOnSaleCount(PaginationForm form, MyList myList) {
        Map<String,Object> query = form.getQueryMap();
        query.put("myListId", myList.getId());
        query.put("onSale", true);

        int onSaleCount = myListItemService.selectCount(query);

        return onSaleCount;
    }

    @Override
    public int getFriendCount(PaginationForm form, Member member){

        Map<String,Object> query = form.getQueryMap();
        query.put("memberId", member.getUser_id());
        int count = myListItemService.selectFriendItemCount(query);

        return count;
    }

}
